C
C     ..................................................................
C
C        SUBROUTINE MSTR
C
C        PURPOSE
C           CHANGE STORAGE MODE OF A MATRIX
C
C        USAGE
C           CALL MSTR(A,R,N,MSA,MSR)
C
C        DESCRIPTION OF PARAMETERS
C           A - NAME OF INPUT MATRIX
C           R - NAME OF OUTPUT MATRIX
C           N - NUMBER OF ROWS AND COLUMNS IN A AND R
C           MSA - ONE DIGIT NUMBER FOR STORAGE MODE OF MATRIX A
C                  0 - GENERAL
C                  1 - SYMMETRIC
C                  2 - DIAGONAL
C           MSR - SAME AS MSA EXCEPT FOR MATRIX R
C
C        REMARKS
C           MATRIX R CANNOT BE IN THE SAME LOCATION AS MATRIX A
C           MATRIX A MUST BE A SQUARE MATRIX
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           LOC
C
C        METHOD
C           MATRIX A IS RESTRUCTURED TO FORM MATRIX R.
C            MSA MSR
C             0   0  MATRIX A IS MOVED TO MATRIX R
C             0   1  THE UPPER TRIANGLE ELEMENTS OF A GENERAL MATRIX
C                    ARE USED TO FORM A SYMMETRIC MATRIX
C             0   2  THE DIAGONAL ELEMENTS OF A GENERAL MATRIX ARE USED
C                    TO FORM A DIAGONAL MATRIX
C             1   0  A SYMMETRIC MATRIX IS EXPANDED TO FORM A GENERAL
C                    MATRIX
C             1   1  MATRIX A IS MOVED TO MATRIX R
C             1   2  THE DIAGONAL ELEMENTS OF A SYMMETRIC MATRIX ARE
C                    USED TO FORM A DIAGONAL MATRIX
C             2   0  A DIAGONAL MATRIX IS EXPANDED BY INSERTING MISSING
C                    ZERO ELEMENTS TO FORM A GENERAL MATRIX
C             2   1  A DIAGONAL MATRIX IS EXPANDED BY INSERTING MISSING
C                    ZERO ELEMENTS TO FORM A SYMMETRIC MATRIX
C             2   2  MATRIX A IS MOVED TO MATRIX R
C
C     ..................................................................
C
      SUBROUTINE MSTR(A,R,N,MSA,MSR)
      DIMENSION A(1),R(1)
C
      DO 20 I=1,N
      DO 20 J=1,N
C
C        IF R IS GENERAL, FORM ELEMENT
C
      IF(MSR) 5,10,5
C
C        IF IN LOWER TRIANGLE OF SYMMETRIC OR DIAGONAL R, BYPASS
C
    5 IF(I-J) 10,10,20
   10 CALL LOC(I,J,IR,N,N,MSR)
C
C        IF IN UPPER AND OFF DIAGONAL  OF DIAGONAL R, BYPASS
C
      IF(IR) 20,20,15
C
C        OTHERWISE, FORM R(I,J)
C
   15 R(IR)=0.0
      CALL LOC(I,J,IA,N,N,MSA)
C
C        IF THERE IS NO A(I,J), LEAVE R(I,J) AT 0.0
C
      IF(IA) 20,20,18
   18 R(IR)=A(IA)
   20 CONTINUE
      RETURN
      END
